using System;
using MvpFramework;
using MvpFramework.UnitTests.Stubs;
using NUnit.Framework;
using Rhino.Mocks;

namespace MvpFramework.UnitTests
{
    [TestFixture]
    public class PresenterFactoryTestFixture
    {
        #region Setup/Teardown

        [SetUp]
        public void SetupTest()
        {
            mocker = new MockRepository();
        }

        #endregion

        private MockRepository mocker { get; set; }

        [Test]
        public void GetPresenterFor_returns_the_Presenter_associated_with_the_identified_view()
        {
            var resolver = mocker.CreateMock<IViewPresenterResolver>();
            var testView = new TestMvpView();
            Type testViewType = typeof (TestMvpView);
            Type presenterType = typeof (TestMvpPresenter);
            var factory = new PresenterFactory(resolver);

            using (mocker.Record())
            {
                SetupResult.For(resolver.GetPresenterTypeFor(testViewType))
                    .IgnoreArguments()
                    .Return(presenterType);
            }
            using (mocker.Playback())
            {
                object presenter = factory.GetPresenterFor(testView);
                Assert.That(presenter is TestMvpPresenter);
            }
        }
        [Test]
        public void GetPresenterFor_does_not_require_a_parameterless_ctor()
        {
            var resolver = mocker.DynamicMock<IViewPresenterResolver>();
            var testView = new TestViewWithDependencies();
            
            SetupResult.For(resolver.GetPresenterTypeFor(null)).
                IgnoreArguments().
                Return(typeof (TestPresenterWithDependencies));
            
            mocker.ReplayAll();

            var factory = new PresenterFactory(resolver);
            var presenter = factory.GetPresenterFor(testView);
            var p = (TestPresenterWithDependencies) presenter;
            Assert.AreEqual(testView, p.TheView);
            
            
            
        }
    }
}